# -*- coding: utf-8 -*-
# @Author: Wolf
# @Date:   2025-03-19 15:53:11
# @Last Modified by:   Wolf
# @Last Modified time: 2025-03-19 16:18:20

import pymysql  
import pymysql.cursors
from flask import Flask, render_template,request
app = Flask(__name__)

@app.route('/add/user',methods=['GET','POST'])
def add_user():
    if request.method == "GET":
        return render_template("add_user.html")
    username = request.form.get("user")
    password = request.form.get("pwd")
    mobile = request.form.get("mobile")

    conn = pymysql.connect(host="192.168.1.215", port=3306, user='root', passwd="123456", charset='utf8',db="unicom")
    cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)
    sql = "insert into admin(username,password,mobile) values(%s,%s,%s)"
    cursor.execute(sql,[username,password,mobile])
    conn.commit()
    cursor.close()
    conn.close()
    return ("添加成功")

@app.route('/show/user',methods=['GET'])
def show_user():
    conn = pymysql.connect(host="192.168.1.215", port=3306, user='root', passwd="123456", charset='utf8',db="unicom")
    cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)
    cursor.execute("select * from admin")
    cursor_list = cursor.fetchall()
    for i in cursor_list:
        print(i)
    cursor.close()
    conn.close()
    return render_template("show_user.html",cursor_list=cursor_list)

if __name__ == '__main__':
    app.run(debug=True,host="0.0.0.0",port=5000)